package com.example.myaop.controller;

import com.example.myaop.annotation.LogAnnotation;
import com.example.myaop.entity.User;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Arrays;
import java.util.List;

/**
 * AOP切面
 */
@RestController
@RequestMapping("/user")
public class UserController {

    @GetMapping("/list")
    public List<User> list() {
        return Arrays.asList(
                new User(1,"刘备"),
                new User(2,"关羽"),
                new User(3,"张飞")
        );
    }

    @GetMapping("/getById/{id}")
    public User getById(@PathVariable("id") Integer id) {
        return new User(1,"刘备");
    }

    @LogAnnotation("新增用户")
    @GetMapping("/save")
    public Boolean save() {
        return true;
    }

    @LogAnnotation("修改用户")
    @GetMapping("/edit")
    public Boolean edit() {
        return true;
    }

    @LogAnnotation("删除用户")
    @GetMapping("/delete/{id}")
    public Boolean delete(@PathVariable("id") Integer id) {
        return true;
    }
}
